import { Db, MongoClient } from "mongodb";
// import { Injectable } from "@nestjs/common";

export class Core {
    private static _ins: Core;
    private client: MongoClient;
    public db: Db;
    constructor() {
        const url = "mongodb://admin:jsz04005301@42.194.197.253:27017";
        this.client = new MongoClient(url);
        // this.connect();
    }

    public async connect(): Promise<void> {
        try {
            await this.client.connect();
            console.log("Connected successfully to server!");
            this.db = this.client.db("book");
        } catch (e) {
            console.error(e);
            console.log("Connected fail to server!");
        }
    }

    static get ins() {
        if (!Core._ins) {
            Core._ins = new Core();
        }
        return Core._ins;
    }
}
